import { connect } from 'dva';
import styles from './styles.less';
import { routerRedux } from 'dva/router';
import MemberInfo from 'components/MemberInfo';
import React, { Component, PropTypes } from 'react';
import { Button, Flex, Modal, Toast, List, WhiteSpace} from 'antd-mobile';

const TongueReady = ({ dispatch, location, localIds, disabled, argument}) => {
  let hg = document.documentElement.clientHeight+"px";
  let mt = ((document.documentElement.clientHeight-279)/3)+"px";
  let ml = ((document.documentElement.clientWidth-323)/2)+"px";
  const onAddto =() => {
      disabled = true;
      dispatch({ type: 'wechat/save', payload: { disabled: disabled}});
  }

  const onClose =() => {
      disabled = false;
      dispatch({ type: 'wechat/save', payload: { disabled: disabled}});
  }
  const onCamera =() => {
     dispatch({
      type: 'wechat/chooseImage',
      payload: {
          sourceType: ['camera'],
          actionType: 'tongue/saveTongueImage',
          onSuccess(payload) {
            dispatch({
              type: 'tongue/saveTongueImage',
              payload:{
                mediaId: payload.image,
                patientId: location.state.patientid,
              },
            });
          },
        },
    });
  }
  const onAlbum =() => {
     dispatch({
      type: 'wechat/chooseImage',
      payload: {
          sourceType: ['album'],
          actionType: 'tongue/saveTongueImage',
          onSuccess(payload) {
            dispatch({
              type: 'tongue/saveTongueImage',
              payload:{
                mediaId: payload.image,
                patientId: location.state.patientid,
              },
            });
          },
        },
    }); 
  }
  return (
     <div className={styles.tab}>

        <img style={{marginTop: mt,marginLeft: ml}}
          src="http://api.tcm-ai.com/dist/77c0439cfafc337de3b16dfef36663b9.png" onClick={onAddto} />
          <Button 
          type="primary" 
          size="large" inline={false} 
          className={styles.btn} 
          style={{backgroundColor: "#efefef",color: "red",border: "2px solid red"}} 
          onClick={onAddto}>
            <span className={styles.btnadd}>+</span>
            添加舌镜照片
          </Button>
          <Modal 
           popup 
           visible={disabled}   
           onClose={onClose}
           animationType="slide-up"
           style={{position: 'fixed',bottom: '0', width: '100%', left: '0'}}>
            <div style={{background:'#efefef'}}>
              <List.Item style={{background:'#efefef'}}>
                <Button style={{color:'#aa4929',fontWeight: 'bold'}} onClick={onCamera}>拍照</Button>
                <Button style={{color:'#aa4929',fontWeight: 'bold'}} onClick={onAlbum}>从相册选择</Button>
              </List.Item>
              <List.Item style={{background:'#efefef'}}>
                <Button style={{color:'#aa4929',fontWeight: 'bold'}} onClick={onClose}>取消</Button>
              </List.Item>
            </div>
          </Modal>
    </div>
  );
};

export default connect(({ wechat }) => ({
  ...wechat,
}))(TongueReady);
